
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nextel.project.cliente.bean;

import pe.com.nextel.rms.DataInputStreamX;
import pe.com.nextel.rms.DataOutputStreamX;
import pe.com.nextel.rms.PersistenteX;
import java.io.IOException;

import org.kxml2.io.KXmlParser;
import org.kxml2.io.KXmlSerializer;
import pe.com.nextel.util.ArrayList;
import pe.com.nextel.util.Iterator;
import pe.com.nextel.util.List;
import pe.com.nextel.util.StringUtils;

/**
 * clase de clientes <br>
 * No agregar mas atributos para no sobrecargar la memoria <br>
 *
 *  
 */
public class ClienteBean extends PersistenteX {
    
    public static final byte ESCOBRABLE = 1;
 
    // datos de negocio
    private long id;
    private String codEmpresa;
    private String codigo;
    private String nombre;
    private String direccion;
    private String tcli_cod;
    private String cli_giro;
    private String cli_secuencia;
    private String deuda;
    private boolean enLinea;
    private String estado;
 
    private List lstIdRecordSet; // lista de idRecordSet del Pedido

    public ClienteBean() {
        setLstIdRecordSet(new ArrayList());
    }

    public void persistir(DataOutputStreamX dataOutput, List list) throws IOException {
 
        dataOutput.writeInt(list.size());

        for (Iterator it = list.iterator(); it.hasNext();) {
            ClienteBean cliente = (ClienteBean) it.next();
            cliente.persistirItem(dataOutput);
        }
    }
    
    
    public void persistirItem(DataOutputStreamX dataOutput) throws IOException {        
        dataOutput.writeShort(this.getPosicionID());
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getCodigo()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getNombre()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getTcli_cod()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getCli_giro()));
        
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getCli_secuencia()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getDireccion()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getCodEmpresa()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getDeuda()));
        dataOutput.writeString(StringUtils.stringNullToBlank(this.getEstado()));
        
        dataOutput.writeLong(this.getId());
    }

    public List recuperar(DataInputStreamX dataInput) throws IOException {
        //System.out.println("recuperar");
        List lista = new ArrayList();
        ClienteBean cliente = null;

        int cant = dataInput.readInt();
        
        for (int i = 0; i < cant; i++) {
            cliente = new ClienteBean();
            cliente.recuperarItem(dataInput);
            lista.add(cliente);
        }

        return lista;
    }

    
    public void recuperarItem(DataInputStreamX dataInput) throws IOException {        
        this.setPosicionID(dataInput.readShort());
        this.setCodigo(dataInput.readString());
        this.setNombre(dataInput.readString());
        this.setTcli_cod(dataInput.readString());
        this.setCli_giro(dataInput.readString());
        
        this.setCli_secuencia(dataInput.readString());
        this.setDireccion(dataInput.readString());
        this.setCodEmpresa(dataInput.readString());
        this.setDeuda(dataInput.readString());
        this.setEstado(dataInput.readString());
        
        this.setId(dataInput.readLong());
 
    }
 

    public void writeXMLObject(KXmlSerializer writer) throws IOException {
        writer.startTag(null, "cl");
        writer.attribute(null, "c", StringUtils.stringNullToBlank(getCodigo()));
        writer.attribute(null, "e", StringUtils.stringNullToBlank(getCodEmpresa()));
     
        writer.endTag(null, "cl");
    }

    public void readXMLObject(KXmlParser parser) throws IOException {
 
    }

 
    public List getLstIdRecordSet() {
        return lstIdRecordSet;
    }

    public void setLstIdRecordSet(List lstIdRecordSet) {
        this.lstIdRecordSet = lstIdRecordSet;
    }

    public void addIdRecordSetPedido(int idRecordSetPedido) {

        for (Iterator it = getLstIdRecordSet().iterator(); it.hasNext();) {
            Integer id = (Integer) it.next();
            if (id.intValue() == idRecordSetPedido) {
                return;
            }
        }
 
        getLstIdRecordSet().add(new Integer(idRecordSetPedido));
    }

    public void clear() {

        if (getLstIdRecordSet() != null) {
            getLstIdRecordSet().clear();
            setLstIdRecordSet(null);
        }
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDireccion() {
        return direccion;
    }

    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public String getDeuda() {
        return deuda;
    }

    public void setDeuda(String deuda) {
        this.deuda = deuda;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTcli_cod() {
        return tcli_cod;
    }

    public void setTcli_cod(String tcli_cod) {
        this.tcli_cod = tcli_cod;
    }

    public String getCli_giro() {
        return cli_giro;
    }

    public void setCli_giro(String cli_giro) {
        this.cli_giro = cli_giro;
    }

    public String getCli_secuencia() {
        return cli_secuencia;
    }

    public void setCli_secuencia(String cli_secuencia) {
        this.cli_secuencia = cli_secuencia;
    }

    public String getCodEmpresa() {
        return codEmpresa;
    }

    public void setCodEmpresa(String codEmpresa) {
        this.codEmpresa = codEmpresa;
    }

    public boolean isEnLinea() {
        return enLinea;
    }

    public void setEnLinea(boolean enLinea) {
        this.enLinea = enLinea;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }


 
}
